classdef LComb
    properties
        String
        Name
    end
    
    
    
    
    methods
        function this = LComb(string, name)
            if nargin==0
                return
            end
            if ischar(string)
                string = { string };
            end
            string = string(:).';
            name = name(:).';
            name = regexptranslate('escape',name);
            nName = length(name);
            for i = 1 : nName
                string = regexprep(string, ['\<',name{i},'\>(?!\{)'], sprintf('?(%g)',i));
            end
            string = strrep(string,'?','x');
            this.String = string;
            this.Name = name;            
        end
        
        
        
        
        function [Z,C,isValid] = convert(this)
            nString = length(this.String);
            nName = length(this.Name);
            Z = nan(nString,nName);
            C = zeros(nString,1);
            isValid = true(1,nString);
            for i = 1 : nString
                try
                    if true % ##### MOSW
                        f = str2func( ['@(x)', this.String{i}] );
                    else
                        f = mosw.str2func( ['@(x)', S{i}] ); %#ok<UNRCH>
                    end
                    x = zeros(1,nName);
                    try
                        C(i) = f(x);
                    catch %#ok<CTCH>
                        C(i) = NaN;
                    end
                    for j = 1 : nName
                        x = zeros(1,nName);
                        x(j) = 1;
                        Z(i,j) = f(x) - C(i);
                    end
                catch
                    isValid(i) = false;
                end
            end
        end 
    end
end